package com.tedu.ivos.dict.controller;

import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import com.tedu.ivos.base.response.JsonResult;
import com.tedu.ivos.dict.pojo.dto.DictQuery;
import com.tedu.ivos.dict.pojo.dto.DictSaveParam;
import com.tedu.ivos.dict.pojo.vo.DictVO;
import com.tedu.ivos.dict.service.DictService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@Slf4j
@Api(tags = "字典模块")
@RequestMapping("/v1/dict/")
public class DictController {

    @Autowired
    private DictService dictService;

    @ApiOperation(value = "查询字典信息")
    @ApiOperationSupport(order = 10)
    @PostMapping("select")
    public JsonResult selectDict(DictQuery dictQuery) {
        log.debug("查询字典信息，参数：{}", dictQuery);
        List<DictVO> list = dictService.selectDict(dictQuery);

        return JsonResult.ok(list);
    }

    @ApiOperation(value = "新增字典")
    @ApiOperationSupport(order = 20)
    @PostMapping("save")
    public JsonResult addDict(DictSaveParam dictSaveParam) {
        log.debug("保存字典，参数：{}", dictSaveParam);
        dictService.saveDict(dictSaveParam);

        return JsonResult.ok();
    }

    @ApiOperation(value = "删除字典")
    @ApiOperationSupport(order = 30)
    @PostMapping("delete/{id}")
    public JsonResult deleteDict(@PathVariable Long id) {
        log.debug("删除字典，参数：{}", id);
        dictService.deleteDict(id);

        return JsonResult.ok();
    }

    @ApiOperation(value = "编辑字典")
    @ApiOperationSupport(order = 40)
    @PostMapping("selectById/{id}")
    public JsonResult selectById(@PathVariable Long id) {
        log.debug("编辑字典，参数：{}", id);
        DictVO dictVO = dictService.selectById(id);

        return JsonResult.ok(dictVO);
    }
}
